package com.vca.admin.controller;

import com.vca.common.page.CommonPage;
import com.vca.common.request.CourseTypeRequest;
import com.vca.common.request.PageParamRequest;
import com.vca.common.response.CourseTypeResponse;
import com.vca.common.result.CommonResult;
import com.vca.common.vo.CourseTypeVo;
import com.vca.service.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chenbing
 * @date 2022/10/18   13:13
 */
@Slf4j
@RestController("CourseTypeController")
@RequestMapping("api/admin/course/type")
@Api(tags = "课程类型控制器")
public class CourseTypeController {
    @Autowired
    private CategoryService categoryService;

    /**
     * @Description:课程类型分页列表
     * @Author: chenBing
     * @Date: 2022/10/18
     */
    @PreAuthorize("hasAuthority('admin:course:type:list')")
    @ApiOperation(value = "课程类型分页列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public CommonResult<CommonPage<CourseTypeResponse>> list(@RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "courseTypeName", required = false) String courseTypeName, @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(categoryService.courseTypeList(status, courseTypeName, pageParamRequest));
    }

    /**
     * @Description:新增课程分类
     * @Author: chenBing
     * @Date: 2022/11/7
     */
    @PreAuthorize("hasAuthority('admin:course:type:add')")
    @ApiOperation(value = "新增课程分类")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public CommonResult<String> addCourseType(@RequestBody CourseTypeRequest request) {
        if (categoryService.addCourseType(request)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * @Description:修改课程分类
     * @Author: chenBing
     * @Date: 2022/11/7
     */
    @PreAuthorize("hasAuthority('admin:course:type:edit')")
    @ApiOperation(value = "修改课程分类")
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public CommonResult<String> editCourseType(@RequestBody CourseTypeRequest request) {
        if (categoryService.editCourseType(request)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * @Description:删除课程分类
     * @Author: chenBing
     * @Date: 2022/11/7
     */
    @PreAuthorize("hasAuthority('admin:course:type:remove')")
    @ApiOperation(value = "删除课程分类")
    @RequestMapping(value = "/remove", method = RequestMethod.DELETE)
    public CommonResult<String> removeCourseType(@RequestParam(value = "cid") Integer cid) {
        if (categoryService.removeCourseType(cid)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
